import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getGisEntityZyData } from '@gis/lib/api';

const typeCodeEnum = {
  '2_03': 'xf', // 消防
  '6_05': 'xfd', // 消防站
  '2_02': 'fx', // 防汛
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type_code];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick(e) {
    // console.log(e);
  }
}

export default class Bhaqffzy extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      type: '2,6',
      area_code: area_code,
    };
    const data = await handleCommonRes(getGisEntityZyData, params);
    return data
      .filter((item) => !!typeCodeEnum[item.type_code] && item.longitude && item.latitude)
      .map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
